﻿Imports DTO
Imports BUS
Public Class ucNhaCungCap

    Dim ncc As New NhaCungCapDTO

    Private Sub barbtnThemNCC_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnThemNCC.ItemClick
        Dim frm As New frmThemNhaCungCap
        frm.ShowDialog()
    End Sub

    Sub LayDSNhaCungCap()
        GCKhuVuc.DataSource = NhaCungCapBUS.LayDSNhaCungCap()
    End Sub

    Private Sub ucNhaCungCap_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        barbtnSuaChuaNCC.Enabled = False
        barbtnXoaNCC.Enabled = False
        barbtnXuatNCC.Enabled = False
        LayDSNhaCungCap()
    End Sub

    Private Sub barbtnXoaNCC_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnXoaNCC.ItemClick
        Try
            If NhaCungCapBUS.XoaNhaCungCap(ncc) Then
                DevExpress.XtraEditors.XtraMessageBox.Show("Xóa thành công nhà cung cấp", "Thông Tin", MessageBoxButtons.OK, MessageBoxIcon.Information)
                LayDSNhaCungCap()
            End If
        Catch ex As Exception
            DevExpress.XtraEditors.XtraMessageBox.Show("Xóa thất bại, nhà cung cấp này đang được sử dụng", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error)
            NhaCungCapBUS.DongKetNoi.Close()
        End Try
    End Sub

    Private Sub GridView1_RowClick(sender As Object, e As DevExpress.XtraGrid.Views.Grid.RowClickEventArgs) Handles GridView1.RowClick
        If e.RowHandle >= 0 Then
            barbtnSuaChuaNCC.Enabled = True
            barbtnXoaNCC.Enabled = True
            ncc.TenNhaCungCap = GridView1.GetRowCellValue(e.RowHandle, GCTenNCC).ToString()
            ncc.MaKhuVuc = GridView1.GetRowCellValue(e.RowHandle, GCKhuVucNCC).ToString()
            ncc.DiaChi = GridView1.GetRowCellValue(e.RowHandle, GCDiaChiNCC).ToString()
            ncc.DienThoai = GridView1.GetRowCellValue(e.RowHandle, GCDienThoaiNCC).ToString()
            ncc.Email = GridView1.GetRowCellValue(e.RowHandle, GCEmailNCC).ToString()
            ncc.Fax = GridView1.GetRowCellValue(e.RowHandle, GCFaxNCC).ToString()
            ncc.MaNhaCungCap = GridView1.GetRowCellValue(e.RowHandle, GCMaNCC).ToString()
            ncc.MaSoThue = GridView1.GetRowCellValue(e.RowHandle, GCMSTNCC).ToString()
            ncc.MaTrangThai = Convert.ToInt32(GridView1.GetRowCellValue(e.RowHandle, GCConQuanLyNCC))
            ncc.NganHang = GridView1.GetRowCellValue(e.RowHandle, GCTenNHncc).ToString()
            ncc.TaiKhoan = GridView1.GetRowCellValue(e.RowHandle, GCSTKNCC).ToString()
        End If
    End Sub

    Private Sub barbtnSuaChuaNCC_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnSuaChuaNCC.ItemClick
        Dim frm As New frmThemNhaCungCap
        frm.Text = "Sữa chửa nhà cung cấp"
        frm.maNCC = ncc.MaNhaCungCap
        frm.tenNCC = ncc.TenNhaCungCap
        frm.dc = ncc.DiaChi
        frm.dt = ncc.DienThoai
        frm.fax = ncc.Fax
        frm.email = ncc.Email
        frm.nh = ncc.NganHang
        frm.mst = ncc.MaSoThue
        frm.stk = ncc.TaiKhoan
        frm.maTT = ncc.MaTrangThai
        frm.kt = 1
        frm.ShowDialog()
    End Sub

    Private Sub barbtnNapLaiNCC_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnNapLaiNCC.ItemClick
        LayDSNhaCungCap()
    End Sub

    Private Sub GridView1_CustomDrawRowIndicator(sender As Object, e As DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs) Handles GridView1.CustomDrawRowIndicator
        If e.RowHandle >= 0 Then
            If e.Info.IsRowIndicator Then
                e.Info.DisplayText = (e.RowHandle + 1).ToString()
            End If
        End If
    End Sub
End Class
